"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShellHelper = void 0;
const Logger_1 = require("./Logger");
const child_process = require('child_process');
class ShellHelper {
    static getOnline(port = 7520) {
        return __awaiter(this, void 0, void 0, function* () {
            // netstat -an |grep 'ESTABLISHED' |grep -i '9201' |wc -l
            let cmd = "netstat -an |grep 'ESTABLISHED' |grep -i '" + port + "' |wc -l";
            return new Promise((resolve, reject) => {
                child_process.exec(cmd, (error, stdout, stderr) => {
                    if (error) {
                        console.log("执行命令出错=getOnline=", error, stderr);
                        return;
                    }
                    let online = parseInt(stdout);
                    Logger_1.Logger.log("getOnline===", stdout, online);
                    resolve(online);
                });
            });
        });
    }
}
exports.ShellHelper = ShellHelper;
